from selenium.webdriver.common.by import By
from base.base import Base

class Page_History(Base):


    topnav_locator = (By.XPATH,'(//li[contains(@class,"ant-menu-overflow-item")])[4]')  
    input_siteseach_locator = (By.XPATH,'(//input[@class="ant-select-selection-search-input"])[1]')
    site_locator = (By.XPATH,'(//div[@class="ant-cascader-menus"]//li)[1]')
    input_seachdevice_locator = (By.XPATH,'//input[@placeholder="设备搜索"]')
    device_errinfo_locator = (By.XPATH,'(//p[@class="ant-empty-description"])[1]')
    device_locator = (By.XPATH,'//span[text()=" xq测试-通用测温"]')                                #####需优化
    device_top_title_locator = (By.XPATH,'//div[@class="ant-card monitor-title"]')
    device_time_locator = (By.XPATH,'(//div[@class="ant-picker ant-picker-range ele-fluid"])[1]')
    select_month_locator = (By.XPATH,'//button[contains(text(),"月")]')   #默认为2025年
    correct_month_locator = (By.XPATH,'//div[text()="6月"]')
    error_month_locator = (By.XPATH,'//div[text()="3月"]')
    start_day_locator = (By.XPATH,'(//div[text()="1"])[1]')
    end_day_locator = (By.XPATH,'(//div[text()="30"])[2]')
    end_day_locator2 = (By.XPATH,'(//div[text()="30"])[1]')
    confirm_btn_locator = (By.XPATH,'//span[text()="确 定"]')
    search_btn_locator = (By.XPATH,'(//span[text()="查 询"])[1]')
    timelist_locator = (By.XPATH,'//td[@class="ant-table-cell ant-table-cell-fix-left ant-table-cell-fix-left-last"]')
    datalist_locator = (By.XPATH,'//tbody[@class="ant-table-tbody"]//td[@class="ant-table-cell"]')
    error_info_locator = (By.XPATH,'(//p[@class="ant-empty-description"])[1]')



    def page_jump(self):
        self.click(self.topnav_locator)

    def input_site(self,sitename):
        self.input(self.input_siteseach_locator,sitename)

    def click_site(self):
        self.click(self.site_locator)


    def input_device(self,devicename):
        self.input(self.input_seachdevice_locator,devicename)
    
    def get_device_errorinfo(self):
        return self.get_text(self.device_errinfo_locator)
    
    def click_device(self):
        self.click(self.device_locator)

    def get_device_title(self):
        return self.get_text(self.device_top_title_locator)

    #历史数据查询
    def click_select_time(self):
        self.click(self.device_time_locator)

    def click_month_btn(self):
        self.click(self.select_month_locator)
    
    def click_correct_month(self):
        self.click(self.correct_month_locator)

    def click_error_month(self):
        self.click(self.error_month_locator)

    def click_start_day(self):
        self.click(self.start_day_locator)

    def click_confirm_btn(self):
        self.click(self.confirm_btn_locator)

    def click_end_day(self,id=1):
        if id == 1:
            self.click(self.end_day_locator)
        elif id ==2:
            self.click(self.end_day_locator2)
    
    def click_search_btn(self):
        self.click(self.search_btn_locator)

    def get_timelist(self):
        values = []
        for elm in self.finds(self.timelist_locator):
            values.append(self.get_text_elm(elm))
        return values 
    
    def get_datalist(self):
        values = []
        for elm in self.finds(self.datalist_locator):
            values.append(self.get_text_elm(elm))
        return values 
    
    def get_error_info(self):
        return self.get_text(self.error_info_locator)
    
